/*
Copyright (C) 1997-2001 Id Software, Inc.

This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  

See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
*/

// Created on 09.01.2004 by RST.
// $Id: SuperAdapter.java,v 1.9 2005/11/20 22:25:28 salomo Exp $
using System;
using Com = Suake2.UI.qcommon.Com;
namespace Suake2.UI.game
{
	
	public abstract class SuperAdapter
	{
		/// <summary>Returns the Adapter-ID. </summary>
		public abstract System.String ID{get;}
		
		/// <summary>Constructor, does the adapter registration. </summary>
		public SuperAdapter()
		{
			register(this, ID);
		}
		
		/// <summary>Adapter registration. </summary>
		private static void  register(SuperAdapter sa, System.String id)
		{
			adapters[id] = sa;
		}
		
		/// <summary>Adapter repository. </summary>
		private static System.Collections.Hashtable adapters = System.Collections.Hashtable.Synchronized(new System.Collections.Hashtable());
		
		/// <summary>Returns the adapter from the repository given by its ID. </summary>
		public static SuperAdapter getFromID(System.String key)
		{
			SuperAdapter sa = (SuperAdapter) adapters[key];
			
			// try to create the adapter
			if (sa == null)
			{
				Com.DPrintf("SuperAdapter.getFromID():adapter not found->" + key + "\n");
			}
			
			return sa;
		}
	}
}